package hashset04;
/*
* 1.自定义的引用数据类型使用默认的hashCode()方法和equals()方法
*   hashCode()方法:默认是根据对象的内存地址值生成哈希值,不同对象生成的哈希值不同
*   equals()方法:默认的是比较对象的内存地址值,相同就返回true,不同就返回false
*
* */
public class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Person person)) return false;

        if (age != person.age) return false;
        return name.equals(person.name);
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + age;
        return result;
    }
}
